<?php
namespace BoxEdu\Controller\Home;
//use Think\Controller;

class GroupController extends CommonController {

	public function _initialize() {
		//
		//dump(date("Y-m-d H:i:s",1474437988));
		parent::_initialize();
		$this->nav_cur = "Group";
	}

	//操作当为空的时候
	public function _empty($name) {
		ob_start();
		$GLOBALS['GETCONTENT'] = 1;
		A("BoxSns/Home/Group")->$name();
		$this->page_content = ob_get_contents();
		ob_end_clean();
		C('DEFAULT_MODULE', "BoxEdu");
		$templateFile = $this->getTemplateFile("Index/home");
		parent::display($templateFile);
	}

	function doc_list() {
		// $data = BoxModel("sns_topic_copy")->where(array('pid' => '87'))->select();
		// $model = BoxModel("sns_topic");
		// $model->where(array('pid' => '87'))->delete();
		// foreach ($data as $k => $one) {
		// 	unset($one['id']);
		// 	$model->add($one);
		// }
		$this->id = I('id');
		$this->cate_id = $cate_id = I('cate_id', "136", "intval");
		$this->group_id = $group_id = I('group_id', "87", "intval");
		$this->list = BoxModel("sns_topic")->get(array('pid' => $group_id, 'type' => "eduGroup", 'is_show' => 1, 'cate_id' => $cate_id), "", "is_top desc,order_by");
		if (!$this->id) {
			$this->id = $this->list['0']['id'];
		}
		$this->data = BoxModel("sns_topic")->load($this->id);
		$this->cateList = BoxModel("addon_category")->get(array('type' => "doc_" . $this->group_id), "", "order_by");
		$this->display();
	}

	function setCode() {
		$key = $this->user_id ? $this->user_id : session_id();
		$html = stripslashes(htmlspecialchars_decode($_POST['html']));
		S("show_code_" . $key, $html);
		echo 1;
	}

	function tiy() {
		//$this->header_nav = "";
		$name = I('name');
		$data = BoxModel("edu_tiy")->where(array('name' => $name))->find();
		$data['content'] = str_replace('src="/jquery/jquery-1.11.1.min.js"', 'src="http://boxphpjs.oss-cn-shanghai.aliyuncs.com/jquery-1.11.3.min.js"', $data['content']);
		$this->data = $data;
		$key = $this->user_id ? $this->user_id : session_id();
		S("show_code_" . $key, $data['content']);
		//dump($data);
		$this->display();
	}

	function show_tiy() {
		$key = $this->user_id ? $this->user_id : session_id();
		$html = S("show_code_" . $key);
		if ($html) {
			echo $html;
			exit();
		}

		$name = I('name');
		$data = BoxModel("edu_tiy")->where(array('name' => $name))->find();
		$data['content'] = str_replace('src="/jquery/jquery-1.11.1.min.js"', 'src="http://boxphpjs.oss-cn-shanghai.aliyuncs.com/jquery-1.11.3.min.js"', $data['content']);
		$this->data = $data;
		$templateFile = $this->getTemplateFile("Group/show_tiy");
		parent::display($templateFile);

	}

}